package pl.prv.polanie.client.filemanager;

//import pl.prv.polanie.client.WidgetsProject;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.LoadListener;
import com.google.gwt.user.client.ui.MouseListenerAdapter;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author Janusz Prokulewicz
 */


public class Link extends Composite implements NestedElement {


	private static final String STYLE__FILE = "swo-File";
	private static final String STYLE__FILE_ICON = "swo-File-fileIcon";
	private static final String STYLE__FILE_NAME = "swo-File-fileName";
	
	private static final String STYLE__FILE_HIGHLIGHTED = "swo-File-highlighted";
	
	
	private static final int FILEICON_CONST_IMAGE = 0;
	private static final int FILEICON_CONST_EMPTY = 1;
	
	
	private final HorizontalPanel mainHP = new HorizontalPanel();
	
	private final HTML fileIconHTML = new HTML();
	private final HTML fileNameHTML = new HTML();
	
	private String titleText;
	private String urlText;
	
	 
	private boolean afterOnMouseEnter = false;
	
	
	public Link(String titleText, String urlText) {
		initWidget(mainHP);

		this.titleText = titleText;
		this.urlText = urlText;
		
		mainHP.setStyleName(STYLE__FILE);
		
		fileIconHTML.setStyleName(STYLE__FILE_ICON);
		fileIconHTML.setHeight(16+"px");
		fileIconHTML.setWidth(20+"px");
		
		
		
		setIcon(FILEICON_CONST_EMPTY);
		
		fileNameHTML.setStyleName(STYLE__FILE_NAME);
		fileNameHTML.setHTML("<a href='" + urlText + "' title='" + urlText + "' target='top' >" + titleText+ "</a>");
		fileNameHTML.setHeight(16+"px");
		
		
		mainHP.add(fileIconHTML);
		mainHP.add(fileNameHTML);
		
		
	}
	
	public void setIcon(int iconConst) {
		String html = "<img src='" + getIconUrl(iconConst) + "' />";
		fileIconHTML.setHTML(html);
	}
	
	public String getIconUrl(int iconConst) {
		String url = "";
		switch (iconConst) {
		case FILEICON_CONST_IMAGE:
			url = "fileicon_image.png";
			break;
		case FILEICON_CONST_EMPTY:
			url = "fileicon_empty.png";
			break;

		default:
			break;
		}
		
		return "swo-images/" + url;
	}
	
}
